package com.qidian.mes.defect.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.defect.mapper.DetectionMapper;
import com.qidian.mes.defect.service.DetectionService;
import com.qidianit.common.pojo.MESResult;
import com.qidianit.common.util.Constant;
import com.qidianit.mes.pojo.Detection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 泽华
 * @Description
 * @Time 2024-10-21 19:28
 */
@Service
public class DetectionServiceImpl implements DetectionService {
    @Autowired
    private DetectionMapper detectionMapper;
    @Override
    public MESResult list(Detection detection, int page, int limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Detection> detections = detectionMapper.selectList(detection);
        PageInfo<Detection> pageInfo = new PageInfo<>(detections);
        // 将pageInfo对象设置到MESResult中
        return MESResult.success(pageInfo);
    }

    @Override
    public MESResult save(Detection detection) {
        return detectionMapper.insert(detection) == 1?MESResult.success():MESResult.error();

    }

    @Override
    public MESResult delete(Long detectionId) {
        Detection detection = new Detection();
        detection.setDetectionId(detectionId);
        detection.setDetectionStatus(Constant.DATA_STATUS_DELETE);
        return MESResult.isSuccess(detectionMapper.deleteById(detection));

    }

    @Override
    public MESResult update(Detection detection) {
        return MESResult.success(200,"ok",detectionMapper.update(detection));
    }

    @Override
    public MESResult selectById(Long detectionId) {
        return MESResult.success(detectionMapper.selectById(detectionId));
    }



}
